DataDirect Test Tutorial

This DataDirect Test tutorial explains how to use the most important features of DataDirect Test (and the JDBC API) and assumes that you can connect to a database with the standard available demo table or fine-tune the sample SQL statements shown in this example as appropriate for your environment.

NOTE: The step-by-step examples used in this tutorial do not show typical clean-up routines (for example, closing result sets and connections). These steps have been omitted to simplify the examples. Do not forget to add these steps when you use equivalent code in your applications.

Configuring DataDirect Test

The default DataDirect Test configuration file is:

install_dir/testforjdbc/Config.txt

where install_dir is your SequeLink for JDBC Driver installation directory. This file can be edited as appropriate for your environment using any text editor. All parameters are configurable, but the most commonly configured parameters are:

Drivers
A list of colon-separated JDBC driver classes.
DefaultDriver
The default JDBC driver that appears in the Get Driver URL window.
Databases
A list of comma-separated JDBC URLs. The first item in the list appears as the default in the database selection window. You can use one of these URLs as a template when you make a JDBC connection. The default Config.txt file contains example URLs for most databases.
InitialContextFactory
Should be set to com.sun.jndi.fscontext.RefFSContextFactory
if you are using file system data sources, or
com.sun.jndi.ldap.LdapCtxFactory
if you are using LDAP.
ContextProviderURL
The location of the .bindings file if you are using file system data sources, or your LDAP Provider URL if you are using LDAP.
Datasources
A list of comma-separated JDBC data sources. The first item in the list appears as the default in the data source selection window.

Starting DataDirect Test

How you start DataDirect Test depends on your platform:

After you start DataDirect Test, the following window appears:

Main JDBCTest window

The main DataDirect Test window shows the following information:

TIP: The DataDirect Test windows contain two Concatenate check boxes. Select a Concatenate check box to see a cumulative record of previous actions; otherwise, only the last action is shown. Selecting Concatenate can degrade performance, particularly when displaying large resultSets.

Connecting Using DataDirect Test

There are two methods to connect using DataDirect Test: through a data source or through driver/database selection.

Connecting Using a Data Source

  1. From the DataDirect Test main window menu, select Connection / Connect to DB via Data Source. DataDirect Test displays the Select A Datasource window.

  2. Select A Datasource window

  3. Select a data source from the Defined Datasources pane. In the User Name and Password fields, type the required user and password connection properties; then, click Connect. See "Developing JDBC Applications" for information about JDBC connection properties.
  4. If the connection was successful, the Connection window appears and displays Connection Established in the JDBC/Database Output scroll box.

  5. Connection window

Connecting Using Driver/Database Selection

  1. From the DataDirect Test main window menu, select Driver / Register Driver. DataDirect Test prompts you for a JDBC driver name.
  2. In the Please Supply a Driver URL field, make sure that a driver is specified, as in the following example; then, click OK.
  3. com.ddtek.jdbc.sequelink.SequeLinkDriver

    If the JDBC driver was registered successfully, the main DataDirect Test window appears with a confirmation in the JDBC/Database Output scroll box.


    Main JDBCTest window with a confirmation message in the JDBC/Database Output scroll box

  4. Select Connection / Connect to DB from the main menu. JDBC prompts with a list of default connection URLs.

  5. Select A Database dialog box with a list of default connection URLs displayed

  6. Select one of the default JDBC driver connection URLs. In the Database field, modify the default values of the connection URL appropriately for your environment.
  7. In the User Name and Password fields, type the required user and password connection properties; then, click Connect. See "Developing JDBC Applications" for information about JDBC connection properties.
  8. If the connection was successful, the Connection window appears and displays Connection Established in the JDBC/Database Output scroll box.

  9. Connection window

Executing a Simple Select Statement

This example explains how to execute a simple Select statement and retrieve the results.

  1. From the Connection window menu, select Connection / Create Statement. The connection window indicates that the creation of the statement was successful.
  2. Select Statement / Execute Stmt Query. DataDirect Test displays a dialog box that prompts for a SQL statement.
  3. Specify the Select statement that you want to execute.

  4. Execute SQL Query dialog box with an example  Select statement specified

    Click Submit; then, click Close.

  5. Select Results / Show All Results. The data from your result set is displayed.

  6. Connection window with an example of result set data displayed

  7. Scroll through the code in the Java Code scroll box to see which JDBC calls have been implemented by DataDirect Test.

Executing a Prepared Statement

This example explains how to execute a parameterized statement multiple times.

  1. From the Connection window menu, select Connection / Create Prepared Statement. DataDirect Test prompts you for a SQL statement.
  2. Specify the Insert statement that you want to execute.

  3. Get Prepared Statement SQL dialog box with an example Insert statement displayed

    Click Submit; then, click Close.

  4. Select Statement / Set Prepared Parameters. To set the value and type for each parameter:
    1. Type the parameter number.
    2. Select the parameter type.
    3. Type the parameter value.
    4. Click Set to pass this information to the JDBC driver.

    5. Set Prepared Statement Parameters dialog box with example values

  5. When you are finished, click Close.
  6. Select Statement / Execute Stmt Update. The JDBC/Database Output scroll box indicates that one row has been inserted.

  7. Connection window showing one row has been inserted

  8. If you want to insert multiple records, repeat Step 3 and Step 5 for each record.
  9. If you repeat the steps described in "Executing a Simple Select Statement", you will see that the previously inserted records are also returned.

  10. Connection window showing that the previously inserted records are also returned

Retrieving Database Metadata

  1. From the Connection window menu, select Connection / Get DB Meta Data.
  2. Select MetaData / Show Meta Data. Information about the JDBC driver and the database to which you are connected is returned.

  3. Connection window showing that information about the JDBC driver and the database to which you are connected is returned

  4. Scroll through the Java code in the Java Code scroll box to find out which JDBC calls have been implemented by DataDirect Test.
  5. Metadata also allows you to query the database catalog (enumerate the tables in the database, for example). In this example, we will query all tables that are owned by the user SCOTT.

  6. Select MetaData / Tables.
  7. In the Schema Pattern field, type SCOTT.

  8. Get Tables dialog box with a value of SCOTT in the Schema Pattern field

  9. Click Ok. The Connection window indicates that getTables() succeeded.
  10. Select Results / Show All Results. All tables owned by SCOTT are returned.

  11. Connection window listing all of the tables owned by SCOTT

Scrolling Through a Result Set

NOTE: Scrollable result sets are supported by JDBC 2.0 and higher and require a Java 2 Platform (J2SE 1.4 or higher)-compatible Java Virtual Machine.

  1. From the Connection window menu, select Connection / Create JDBC 2.0 Statement. DataDirect Test prompts you for a result set type and concurrency.
  2. In the resultSetType field, select TYPE_SCROLL_SENSITIVE. In the resultSetConcurrency field, select CONCUR_READ_ONLY.

  3. Get JDBC 2.0 Statement Properties dialog box with specified values

    Click Submit; then, click Close.

  4. Select Statement / Execute Stmt Query.
  5. Specify the Select statement that you want to execute.

  6. Execute SQL Query dialog box with an example Select statement

    Click Submit; then, click Close.

  7. Select Results / Scroll Results. The Scroll Result Set window indicates that the cursor is positioned before the first row.

  8. Scroll Result Set dialog box indicating that the cursor is positioned before the first row

  9. Click the Absolute, Relative, Before, First, Prev, Next, Last, and After buttons as appropriate to navigate through the result set. After each action, the Scroll Result Set window displays the data at the current position of the cursor.

  10. Scroll Result Set dialog box displaying the data at the current position of the cursor

  11. Click Close.

Batch Execution on a Prepared Statement

Batch execution on a prepared statement allows you to update or insert multiple records simultaneously. In some cases, this can significantly improve system performance because fewer round-trips to the database are required.

NOTE: Batch execution on a prepared statement is supported by the JDBC 2.0 and higher specifications and requires a Java 2 Platform (J2SE 1.4 or higher)-compatible Java Virtual Machine.

  1. From the Connection window menu, select Connection / Create Prepared Statement.
  2. Specify the Insert statement that you want to execute.

  3. Get Prepared Statement SQL dialog box with an example Insert statement

    Click Submit; then, click Close.

  4. Select Statement / Add Stmt Batch.
  5. For each parameter:
    1. Type the parameter number.
    2. Select the parameter type.
    3. Type the parameter value.
    4. Click Set.

    5. Set Batch Parameters dialog box with example values specified

  6. Click Add to add the specified set of parameters to the batch. To add multiple parameter sets to the batch, repeat Step 3 through Step 5 as many times as necessary. When you are finished adding parameter sets to the batch, click Close.
  7. Select Statement / Execute Stmt Batch. DataDirect Test displays the rowcount for each of the elements in the batch.

  8. Connection window displaying the rowcount for each of the elements in the batch

  9. If you re-execute the Select statement from "Executing a Simple Select Statement", you see that the previously inserted records are returned.
  10. .
    Connection window showing that the previously inserted records are returned

Returning ParameterMetaData

NOTE: Returning ParameterMetaData is a JDBC 3.0 feature and requires a J2SE 1.4 or higher Java Virtual Machine.

  1. From the Connection window menu, select Connection / Create Prepared Statement.
  2. Specify the prepared statement that you want to execute.

  3. Get Prepared Statement SQL dialog box with an example Insert statement

    Click Submit; then, click Close.

  4. Select Statement / Get ParameterMetaData. The Connection window displays ParameterMetaData.

  5. Connection window showing ParameterMetaData

Establishing Savepoints

NOTE: Savepoints is a JDBC 3.0 feature and requires a J2SE 1.4 or higher Java Virtual Machine.

  1. From the Connection window menu, select Connection / Connection Properties.
  2. Select TRANSACTION_COMMITTED from the Transaction Isolation drop-down list. Do not select the Auto Commit check box.

  3. Connection Properties dialog box

    Click Set; then, click Close.

  4. From the Connection window menu, select Connection / Load and Go. The Get Load And Go SQL window appears.
  5. Specify the statement that you want to execute.

  6. Get Load And Go SQL window

    Click Submit.

  7. Select Connection / Set Savepoint. In the Set Savepoints window, specify a savepoint name.

  8. Set Savepoints window

    Click Apply; then, click Close. The Connection window indicates whether or not the savepoint succeeded.


    Connection window

  9. Return to the Get Load And Go SQL window and specify another statement.

  10. Get Load And Go SQL window

    Click Submit.

  11. Select Connection / Rollback Savepoint. In the Rollback Savepoints window, specify the savepoint name.

  12. Rollback Savepoints window

    Click Apply; then, click Close. The Connection window indicates whether or not the savepoint rollback succeeded.


    Connection window

  13. Return to the Get Load And Go SQL window and specify another statement.

  14. Get Load And Go SQL window

    Click Submit; then, click Close.

    The Connection window displays data that was inserted before the first Savepoint. The second insert was rolled back.


    Connection window

Updatable Result Sets

The following examples illustrate Updatable result sets by deleting, inserting, and updating a row.

Deleting a Row

  1. From the Connection window menu, select Connection / Create JDBC 2.0 Statement.
  2. In the resultSetType field, select TYPE_SCROLL_SENSITIVE. In the resultSetConcurrency field, select CONCUR_UPDATABLE.

  3. Get JDBC 2.0 Statement Properties dialog box

    Click Submit; then, click Close.

  4. Select Statement / Execute Stmt Query.
  5. Specify the Select statement that you want to execute.

  6. Execute SQL Query dialog box with an example Select statement

    Click Submit; then, click Close.

  7. Select Results / Inspect Results. The Inspect Result Set window is displayed.

  8. Inspect Result Set window

  9. Click Next. Current Row changes to 1.
  10. Click Delete Row.
  11. To verify the result, return to the Connection menu and select Connection / Load And Go. The Get Load and Go SQL window appears.
  12. Specify the statement that you want to execute.

  13. Get Load And Go SQL window

    Click Submit; then, click Close.

  14. The Connection window shows one row returned.

  15. Connection window

Inserting a Row

  1. From the Connection window menu, select Connection / Create JDBC 2.0 Statement.
  2. In the resultSetType field, select TYPE_SCROLL_SENSITIVE. In the resultSetConcurrency field, select CONCUR_UPDATABLE.

  3. Get JDBC 2.0 Statement Properties dialog box

    Click Submit; then, click Close.

  4. Select Statement / Execute Stmt Query.
  5. Specify the Select statement that you want to execute.

  6. Execute SQL Query window with an example Select statement

    Click Submit; then, click Close.

  7. Select Results / Inspect Results. The Inspect Result Set window is displayed.

  8. Inspect Result Set window

  9. Click Move to insert row; Current Row is now Insert row.
  10. Change Data Type to int. In Set Cell Value, enter 20. Click Set Cell.
  11. Select the second row in the top pane. Change the Data Type to String. In Set Cell Value, enter RESEARCH. Click Set Cell.
  12. Select the third row in the top pane. In Set Cell Value, enter DALLAS. Click Set Cell.
  13. Click Insert Row.
  14. To verify the result, return to the Connection menu and select Connection / Load And Go. The Get Load and Go SQL window appears.
  15. Specify the statement that you want to execute.

  16. Get Load And Go SQL window

    Click Submit; then, click Close.

  17. The Connection window shows two rows returned.

  18. Connection window

Note that the ID will be 3 for the row just inserted, because it is an auto increment column.

Updating a Row

  1. From the Connection window menu, select Connection / Create JDBC 2.0 Statement.
  2. In the resultSetType field, select TYPE_SCROLL_SENSITIVE. In the resultSetConcurrency field, select CONCUR_UPDATABLE.

  3. Get JDBC 2.0 Statement Properties dialog box

    Click Submit; then, click Close.

  4. Select Statement / Execute Stmt Query.
  5. Specify the Select statement that you want to execute.

  6. Execute SQL Query dialog box with an example Select statement

    Click Submit; then, click Close.

  7. Select Results / Inspect Results. The Inspect Result Set window is displayed.

  8. Inspect Result Set window

  9. Click Next. Current Row changes to 1.
  10. In Set Cell Value, enter RALEIGH. Click Set Cell.
  11. Click Update Row.
  12. To verify the result, return to the Connection menu and select Connection / Load And Go. The Get Load and Go SQL window appears.
  13. Specify the statement that you want to execute.

  14. Get Load And Go SQL window

    Click Submit; then, click Close.

  15. The Connection window shows LOC for accounting changed from NEW YORK to RALEIGH.

  16. Connection window

LOB Support

NOTE: LOB support (Blobs and Clobs) is a JDBC 3.0 feature and requires a J2SE 1.4 or higher Java Virtual Machine.

The following example uses CLOB data; however, this procedure also applies to BLOB data. This example illustrates only one of several ways in which LOB data can be processed.

  1. From the Connection window menu, select Connection / Create Statement.
  2. Select Statement / Execute Stmt Query.
  3. Specify the Select statement that you want to execute.

  4. Execute SQL Query window with an example Select statement

    Click Submit; then, click Close.

  5. Select Results / Inspect Results. The Inspect Result Set window is displayed.
  6. Click Next. Current Row changes to 1.

  7. Inspect Result Set window

  8. Deselect Auto Traverse. This disables automatic traversal to the next row.
  9. Click Get Cell.

  10. Inspect Result Set window

  11. Values are returned in the Get Cell Value field.
  12. Change the Data Type to Clob.

  13. Inspect Result Set window

  14. Click Get Cell. The Clob data window appears.

  15. Clob Data dialog box

  16. Click Get Cell.

  17. Clob Data dialog box

  18. Values are returned in the Cell Value field.